﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Models;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectTimeHandler
{
    public class GetLastestProjectTime
    {
        private readonly ProjectTimeRepository _projectTimeRepository;

        public GetLastestProjectTime(ProjectTimeRepository projectTimeRepository)
        {
            _projectTimeRepository = projectTimeRepository;
        }
        public GetLastestProjectTime()
        {
            _projectTimeRepository = new ProjectTimeRepository();
        }
        public virtual ProjectTimeModel Execute(string userid)
        {
            ProjectTimeModel projectTimeModel = null;
            try
            {
                // try to get from db
                project_times projectTimesData = _projectTimeRepository.GetLastProjectTime(userid);

                // parse to business model
                if (projectTimesData != null)
                {
                    projectTimeModel = new ProjectTimeModel(projectTimesData);
                }
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
            }

            return projectTimeModel;

        }
    }
}
